Hello Phalcon,

i found a different behaviour beetween the new and the previous version of Phalcon in the ORM, and in particular during a save() action of one model related to another:

I explain the behaviour for the two version: Suppose that we have this two models: User and UserImage.

One related to the other:

class User {
    public $id
    public $name;
    public function initialize()
    {
        $this->hasOne('id','UserImage', 'fk_user',  array('alias' => 'Image'));
    }
    public function validation()
    {
        $this->validate(new PresenceOf(array( 'field' => 'name')));
        return $this->validationHasFailed() != true;
    }
}

class UserImage {
    public $fk_user;
    public $image;
    public function initialize()
    {
        parent::initialize();
        $this->hasOne('fk_user','User', 'id', array('alias' => 'User')));
    }
    public function validation()
    {
        $this->validate(new PresenceOf(array( 'field' => 'image')));
        return $this->validationHasFailed() != true;
    }
}

And this is the code that i want to execute:

$user = new User();
$user->name = 'Mariano Pirelli';

$image = new UserImage();
$image->image = null;

$user->Image = $image;

$user->save();

With Phalcon 1.3

The User validation() is called and return | success because name is valorized

Image validation() is called and return | fail beacuse image is null

And finally all others operations will be cancelled;

Right for me.

With Phalcon 2.0

The User validation() is called and return | success because name is valorized

The User beforeSave() method is called now

Image validation() is called and return | fail beacuse image is null

And finally all others operations will be cancelled;

In this case i would expect that the beforeSave() method will not called until the validation of all the others related models, as in Phalcon 1.3

Is this a bug ? or is it voluntary ?

Finally

I have another question about this, why don't you validate all the models together before to give an error back ? Phalcon validates before User, and then UserImage, so that until the User will not pass the validation you don't validates UserImage, and i cannot display to the user the errors together.

Thank you for the work u done Mariano